import requests
import os


def TranslateTrumpCN(text):
    url = "https://api.deepseek.com/v1/chat/completions"

    KEY = os.environ.get("DEEPSEEK_KEY")
    print(KEY)
    if KEY is None:
        raise RuntimeError("没有设置环境变量 DEEPSEEK_KEY")

    headers = {
        "Authorization": f"Bearer {KEY}",
        "Content-Type": "application/json"
    }
    
    # 构建翻译指令
    prompt = f"请将以下内容翻译成中文，使用特朗普的语气，忽略[]中的内容，只返回翻译结果：\n{text}"
    
    payload = {
        "model": "deepseek-chat",  # 使用最新模型
        "messages": [
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.3,       # 降低随机性保证翻译准确
    }
    
    response = requests.post(url, json=payload, headers=headers)
    
    if response.status_code == 200:
        result = response.json()
        return result['choices'][0]['message']['content'].strip()
    else:
        raise Exception(f"API Error {response.status_code}: {response.text}")


if __name__ == "__main__":
    print(TranslateTrumpCN("I am pleased to announce that ground has been broken on the White House grounds to build the new, big, beautiful White House Ballroom. Completely separate from the White House itself, the East Wing is being fully modernized as part of this process, and will be more beautiful than ever when it is complete! For more than 150 years, every President has dreamt about having a Ballroom at the White House to accommodate people for grand parties, State Visits, etc. I am honored to be the first President to finally get this much-needed project underway — with zero cost to the American Taxpayer! The White House Ballroom is being privately funded by many generous Patriots, Great American Companies, and, yours truly. This Ballroom will be happily used for Generations to come! President DJT"))
